<template>
  <div>
    <TopFilter :list="partSellList" :cols="3" :labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="multiple"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.onChangeColumn = arr)"
    >
      <template slot="controls">
        <!-- <el-button @click="openPayments" type="primary" >收 款</el-button> -->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryPartPeriodSumReport } from '@/api/part/report/partreport';
import { getStroageList } from '@/api/part/partOutbound/partBreak';

export default {
  name: 'partSell',
  mixins: [dictionary],
  data() {
    return {
      partSellList: this.createPartInfoFilterList(),
      columns: this.createPartColumns(),
      fetchParams: { xhrAbort: true },
      fetchApi: queryPartPeriodSumReport,
      onChangeColumn: []
    };
  },
  mounted() {
    this.initSelect();
  },

  methods: {
    async initSelect() {
      const res = await getStroageList();
      this.columns.find(x => x.dataIndex === 'STORAGE_CODE').editItems = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE + '' }));
    },
    createPartInfoFilterList() {
      return [
        {
          type: 'DATE',
          dateType: 'month',
          label: '年月',
          fieldName: 'yearMonth',
          style: { minWidth: '100px' },
          rules: [{ required: true, message: '年月不可以为空', trigger: 'change' }]
        }
      ];
    },
    createPartColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filterType: 'input'
        },
        {
          title: '期初金额',
          dataIndex: 'OPEN_AMOUNT',
          sorter: true
        },
        {
          title: '期末金额',
          dataIndex: 'CLOSE_AMOUNT',
          sorter: true
        },
        {
          title: '入库金额',
          dataIndex: 'STOCK_IN_AMOUNT',
          sorter: true
        },
        {
          title: '移库入库金额',
          dataIndex: 'TRANSFER_IN_AMOUNT',
          sorter: true
        },
        {
          title: '出库成本金额',
          dataIndex: 'STOCK_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '出库金额',
          dataIndex: 'OUT_AMOUNT',
          sorter: true
        },
        {
          title: '移库出库金额',
          dataIndex: 'TRANSFER_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '采购入库金额',
          dataIndex: 'BUY_IN_AMOUNT',
          sorter: true
        },
        {
          title: '调拨入库金额',
          dataIndex: 'ALLOCATE_IN_AMOUNT',
          sorter: true
        },
        {
          title: '其它入库金额',
          dataIndex: 'OTHER_IN_AMOUNT',
          sorter: true
        },
        {
          title: '报溢入库金额',
          dataIndex: 'PROFIT_IN_AMOUNT',
          sorter: true
        },
        {
          title: '维修领料成本金额',
          dataIndex: 'REPAIR_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '配件销售成本金额',
          dataIndex: 'SALE_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '配件销售销售金额',
          dataIndex: 'SALE_OUT_SALE_AMOUNT',
          sorter: true
        },
        {
          title: '内部领用销售金额',
          dataIndex: 'INNER_OUT_SALE_AMOUNT',
          sorter: true
        },
        {
          title: '内部领用成本金额',
          dataIndex: 'INNER_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '调拨出库成本金额',
          dataIndex: 'ALLOCATE_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '调拨出库销售金额',
          dataIndex: 'ALLOCATE_OUT_SALE_AMOUNT',
          sorter: true
        },
        {
          title: '其它出库成本金额',
          dataIndex: 'OTHER_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '发料调整差异金额',
          dataIndex: 'OTHER_OUT_SALE_AMOUNT',
          sorter: true
        },
        {
          title: '报损出库金额',
          dataIndex: 'LOSS_OUT_AMOUNT',
          sorter: true
        },
        {
          title: '维修领料销售金额',
          dataIndex: 'REPAIR_OUT_SALE_AMOUNT',
          sorter: true
        },
        {
          title: '不含移库的入库金额',
          dataIndex: 'NO_TRANSFER_STOCK_IN_AMOUNT',
          sorter: true
        },
        {
          title: '不含移库的出库金额',
          dataIndex: 'NO_TRANSFER_OUT_AMOUNT',
          sorter: true
        },
        {
          title: '不含移库出库成本金额',
          dataIndex: 'NO_TRANSFER_STOCK_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '装潢领料成本金额',
          dataIndex: 'UPHOLSTER_OUT_COST_AMOUNT',
          sorter: true
        },
        {
          title: '装潢领料销售金额',
          dataIndex: 'UPHOLSTER_OUT_SALE_AMOUNT',
          sorter: true
        }
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  }
};
</script>

<style scoped lang="less"></style>
